package org.algorithm.biubiu.wheel_1.common;

/**
 * @Date 2022/2/11 19:49
 * @Created by biubiu
 */
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    public  ListNode(int... nums) {
    }
    public ListNode() {
    }

    public static String print(ListNode node) {
        ListNode tmp = node;
        StringBuilder sb = new StringBuilder();
        while (tmp != null) {
            sb.append(tmp.val).append(",");
            tmp = tmp.next;
        }
        return sb.subSequence(0, sb.length() - 1).toString();
    }

    public static ListNode build(int... nums) {
      ListNode root = new ListNode();
      ListNode dummy = root;
        for (int num : nums) {
            ListNode listNode = new ListNode(num);
            dummy.next = listNode;
            dummy = listNode;
        }
        return root.next;
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                ", next=" + next +
                '}';
    }
}
